use std::{fs, process::Command};

use anyhow::Result;

// prost 只能编译proto的message，还不能编译service
// 需要使用tonic，tonic-build编译service

fn main() -> Result<()> {
    let path = "src/pb";
    // Recursively create a directory and all of its parent components if they are missing
    fs::create_dir_all(path)?;
    let builder = tonic_build::configure();
    builder.out_dir(path).compile_protos(
        &["./protos/messages.proto", "./protos/dfs.proto"],
        &["./protos"],
    )?;
    Command::new("cargo").args(["fmt", "--all"]).output()?;
    println!("cargo:rerun-if-changed=protos/dfs.proto");
    println!("cargo:rerun-if-changed=protos/messages.proto");
    Ok(())
}
